package com.esa.servlet.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.esa.dbi.AccountDBI;
import com.esa.dbi.impl.AccountDBImpl;
import com.esa.javabean.Account;


public class LoginServlet extends HttpServlet {
	private AccountDBI adbi= new AccountDBImpl();
	 
	 public void doGet(HttpServletRequest request, HttpServletResponse response)
	   throws ServletException, IOException {
	  doPost(request,response);
	 }

	 public void doPost(HttpServletRequest request, HttpServletResponse response)
	   throws ServletException, IOException {
	  
	  String acname = request.getParameter("acname");
	  String password = request.getParameter("password");
	  Account acnt=new Account();
	  acnt.setAcname(acname);
	  acnt.setPassword(password);
	  boolean b = false;
	  b = adbi.validate(acnt);
	  String str=adbi.getAccount(acname).getLevel();
	  
	  if(b == true){
		  if(str=="0".toString()){  
		  response.sendRedirect("NHomeServlet");
		  }
		  else if(str=="1"){
			response.sendRedirect("AHomeServlet");
		  }
	  }else{
	   request.getRequestDispatcher("loginerror.jsp").forward(request, response);
	  }
	  
	 }
}
